package com.djinfo.work.controller;

/**
 * Created by lenovo on 2017/5/17.
 */

import com.djinfo.work.common.bean.AjaxJson;
import com.djinfo.work.common.util.StringUtil;
import com.djinfo.work.entity.Department;
import com.djinfo.work.entity.TbSysUsers;
import com.djinfo.work.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 部门
 */
@Controller
@RequestMapping("/department")
public class DepartmentController {
    /**
     * 自动注入
     */
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private com.djinfo.work.service.UserService UserService;

    /**
     * 部门列表
     */
    @RequestMapping("/list.do")
    @ResponseBody
    public AjaxJson list(Department department, Integer pagenum, Integer pagesize){
        AjaxJson ajaxJson = departmentService.list(department,pagenum,pagesize);
        return ajaxJson;
    }

    /**
     *给用户分配部门
     */
    @RequestMapping("/list2.do")
    @ResponseBody
    public AjaxJson deptList(String uid){
        AjaxJson ajaxJson=departmentService.deptList(uid);
        return ajaxJson;
    }

    /**
     * 获取部门对象信息
     */
    @RequestMapping("/info.do")
    public ModelAndView info(Department department){
        if(department.getId()==null){
            department=new Department();
        }else {
            department = departmentService.getDepartmentById(department.getId());
        }
        return new ModelAndView("department/createDept.html","department",department);
    }
    @RequestMapping("/getLevel1DeptList.do")
    @ResponseBody
    public AjaxJson getDeptList(){
        AjaxJson ajaxJson = departmentService.getDeptList();
        return ajaxJson;
    }


    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate.do")
    @ResponseBody
    public AjaxJson saveOrUpdate(Department department,HttpServletRequest request){
        AjaxJson ajaxJson = departmentService.saveOrUpdate(department,request);
        return ajaxJson;
    }
    /**
     * 删除
     */
    @RequestMapping("/delete.do")
    @ResponseBody
    public AjaxJson delete(Department department){
        AjaxJson ajaxJson = departmentService.deleteDept(department);
        return ajaxJson;
    }


    /**
     * 批量删除
     *//*
    @RequestMapping("/deleteSome.do")
    @ResponseBody
    public AjaxJson deleteSome(String[] ids){
        AjaxJson ajaxJson = new AjaxJson();
        for(int i=0;i<ids.length;i++){
            Department department=departmentService.getDepartmentById(ids[i]);
            departmentService.delete(department);
        }
        ajaxJson.setCode(101);
        ajaxJson.setMsg("success");
        return ajaxJson;
    }*/


    @RequestMapping("/allDeptList.do")
    @ResponseBody
    public AjaxJson deptList(Department department){
        AjaxJson ajaxJson = departmentService.deptList(department);
        return ajaxJson;
    }




}
